#ifndef __WSJOINSERVER_H__
#define __WSJOINSERVER_H__

#pragma once

#include "..\common\MyWinsockBase.h"

#define MAX_SOCKETINDEX		65536

#define MAX_SOCKETBUFFER	100

#define MAX_SENDBUFSIZE 500000
#define MAX_RECVBUFSIZE	500000

class CSocketBuffer
{
public:
	int		live;
	char	Ip_addr[16];

	SOCKET	m_socket;

	BYTE	m_SendBuf[MAX_SENDBUFSIZE];
	int		m_SendBufLen;

	BYTE	m_RecvBuf[MAX_RECVBUFSIZE];
	int		m_RecvBufLen;

public:
	CSocketBuffer()
	{
		Clear();
	};
	void Clear()
	{
		live = 0;
		memset(Ip_addr, 0, 16);
		memset(m_SendBuf, 0, MAX_SENDBUFSIZE);
		memset(m_RecvBuf, 0, MAX_RECVBUFSIZE);
		m_socket = INVALID_SOCKET;
		m_SendBufLen = 0;
		m_RecvBufLen = 0;
	};
};

class CwsJoinServer : public MyWinsockBase
{
public:
	int		m_SockIndex[MAX_SOCKETINDEX];

	CSocketBuffer	sb[MAX_SOCKETBUFFER];

	DWORD	m_WinClientMsg;

public:
	int SetSocketBuffer(int index, SOCKET socket, char * ip);
	BOOL AcceptSocket(SOCKET & clientSocket, IN_ADDR & cInAddr);
	int  DataRecv(SOCKET socket);
	BOOL FDWRITE_MsgDataSend(SOCKET socket);
	BOOL DataSend(short uindex, char * buf, int len);
	BOOL CreateServer(char * ip_addr, WORD port, DWORD WinServerMsg, DWORD WinClientMsg);

	CwsJoinServer();
	virtual ~CwsJoinServer();
};

#endif